package com.sugon.cloudalibabaorder83.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * 订单控制器
 *
 * @author JH
 * @version 1.0
 * @since 2023/2/20 13:05
 */
@RestController
public class OrderController {

    // 从配置文件中读取
    @Value("${service-url.nacos-user-service}")
    private String serviceUrl;

    @Resource
    RestTemplate restTemplate;

    //83 调动 9001 or 9002 对外暴露的rest接口
    @GetMapping("/consumer/payment/nacos/{id}")
    public String paymentInfo(@PathVariable("id")Long id) {
        //restTemplate.getForObject(url)
        //通过getForObject()发送请求时，会根据响应类型实例化一个AcceptHeaderRequestCallback对象
        // 通过响应类型和消息转换器实例化HttpMessageConverterExtractor对象
        // 最后通过execute()方法执行http请求，核心逻辑在这个方法中
        return restTemplate.getForObject(serviceUrl + "/payment/nacos/" + id, String.class);
    }
}
